import { Controller, Get, Post, Body, Patch, Param, Delete, Query, Req } from "@nestjs/common";
import { UserSubuserService } from "./user-subuser.service";
import { CreateUserSubuserDto } from "./dto/create-user-subuser.dto";
import { UpdateUserSubuserDto } from "./dto/update-user-subuser.dto";
import { ApiBearerAuth, ApiOperation, ApiTags } from "@nestjs/swagger";
import { UserAddSubUserDto } from "@/modules/system/user-subuser/dto/userAddSubUserDto";
import { GetRoleIdByUserIdDto } from "@/modules/system/user-role/dto/getRoleIdByUserId.dto";

@Controller("system/user-subuser")
@ApiTags('用户与子用户相关')
@ApiBearerAuth()
export class UserSubuserController {
    constructor(private readonly userSubuserService: UserSubuserService) {
    }
    
    @Post()
    create(@Body() createUserSubuserDto: CreateUserSubuserDto) {
        return this.userSubuserService.create(createUserSubuserDto);
    }
    
    @Get("getSubUserIdByUserId")
    @ApiOperation({ summary: "更具userId查询userId" })
    getSubUserIdByUserId(@Query() dto: GetRoleIdByUserIdDto) {
        return this.userSubuserService.getSubUserIdByUserId(dto);
    }
    
    @Get("getSubUserInfo")
    @ApiOperation({ summary: "更具token查询userInfo" })
    getSubUserInfo(@Req() req) {
        return this.userSubuserService.getSubUserInfo(req);
    }
    
    @Get()
    @ApiOperation({summary:'列表'})
    findAll(@Query() findAllDto) {
        return this.userSubuserService.findAll(findAllDto);
    }
    
    @Get(":id")
    findOne(@Param("id") id: string) {
        return this.userSubuserService.findOne(+id);
    }
    
    @Patch(":id")
    update(@Param("id") id: string, @Body() updateUserSubuserDto: UpdateUserSubuserDto) {
        return this.userSubuserService.update(+id, updateUserSubuserDto);
    }
    
    @Delete(":id")
    remove(@Param("id") id: string) {
        return this.userSubuserService.remove(+id);
    }
    
    @Post("userAddSubUser")
    @ApiOperation({ summary: "用户添加子用户" })
    userAddSubUser(@Body() userAddSubUserDto:UserAddSubUserDto) {
        return this.userSubuserService.userAddSubUser(userAddSubUserDto);
    }
    
}
